package com.hpjpw.ido.controller;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hpjpw.ido.domain.Area;
import com.hpjpw.ido.service.IAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地区Controller
 * 
 * @author hpj
 * @date 2021-01-03
 */
@Api(value ="AreaController")
@RestController
@RequestMapping("/ido/area")
public class AreaController extends BaseController
{
    @Autowired
    private IAreaService areaService;

    /**
     * 查询地区列表
     */
    @PreAuthorize("@ss.hasPermi('ido:area:list')")
    @GetMapping("/list")
    @ApiOperation("查询地区列表")
    public TableDataInfo list(Area area)
    {
        startPage();
        List<Area> list = areaService.selectAreaList(area);
        return getDataTable(list);
    }

    /**
     * 导出地区列表
     */
    @PreAuthorize("@ss.hasPermi('ido:area:export')")
    @Log(title = "地区", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出地区列表")
    public AjaxResult export(Area area)
    {
        List<Area> list = areaService.selectAreaList(area);
        ExcelUtil<Area> util = new ExcelUtil<Area>(Area.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 获取地区详细信息
     */
    @PreAuthorize("@ss.hasPermi('ido:area:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取地区详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(areaService.selectAreaById(id));
    }

    /**
     * 新增地区
     */
    @PreAuthorize("@ss.hasPermi('ido:area:add')")
    @Log(title = "地区", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增地区")
    public AjaxResult add(@RequestBody Area area)
    {
        return toAjax(areaService.insertArea(area));
    }

    /**
     * 修改地区
     */
    @PreAuthorize("@ss.hasPermi('ido:area:edit')")
    @Log(title = "地区", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改地区")
    public AjaxResult edit(@RequestBody Area area)
    {
        return toAjax(areaService.updateArea(area));
    }

    /**
     * 删除地区
     */
    @PreAuthorize("@ss.hasPermi('ido:area:remove')")
    @Log(title = "地区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除地区")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(areaService.deleteAreaByIds(ids));
    }
}
